package com.lb.shopguide.ui.dialog;

import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.lb.baselib.base.DialogBase;
import com.lb.shopguide.R;

/**
 * Created by kang on 2017/9/8.
 */

public class DialogSetSuccess extends DialogBase {

    private TextView tvContent;

    public static DialogSetSuccess getDialogSetSuccess() {
        DialogSetSuccess dialogSetSuccess = new DialogSetSuccess();
        return dialogSetSuccess;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View mFragmentView = inflater.inflate(R.layout.dialog_set_success, container, false);
        initData();
        initView(mFragmentView);

//        setDialogPosition();
        bindData();
        return mFragmentView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setStyle(STYLE_NO_TITLE, R.style.Theme_Base_AppCompat_Dialog_Light);
    }

    @Override
    public void onStart() {
        super.onStart();
        Dialog dialog = getDialog();
        if (dialog != null) {
            DisplayMetrics dm = new DisplayMetrics();
            getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
            dialog.getWindow().setLayout((int) (dm.widthPixels * 0.75), ViewGroup.LayoutParams.WRAP_CONTENT);
            dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        }
    }

    @Override
    public void onDismiss(DialogInterface dialog) {
        super.onDismiss(dialog);
        if (mOnDialogClickListener != null) {
            mOnDialogClickListener.onSure();
        }
    }

    private void initData() {

    }

    private void initView(View view) {
        tvContent = view.findViewById(R.id.tv_content);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                DialogSetSuccess.this.dismiss();
            }
        }, 1500);
    }

    private void bindData() {

    }

    public interface OnDialogClickListener {
        void onSure();
    }

    private OnDialogClickListener mOnDialogClickListener;

    public void setOnDialogClickListener(OnDialogClickListener listener) {
        mOnDialogClickListener = listener;
    }
}
